package com.ld.xuanKe.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public  class HibernateUtil {
	@Resource
	private SessionFactory sessionFactory;
	public  Session getSession() {//获取Session对象的方法

		return sessionFactory.openSession();


	}

	public  void closeSession(Session session) {//释放Session对象的方法
		if(session != null){
			session.close();
		}
	}
}
